<?php
declare (strict_types = 1);

namespace app\listener;

class WsJoin
{
    /**
     * 加入房间事件监听处理
     *
     * @return mixed
     */
    public function handle($event)
    {

        //var_dump($event);
        $ws = app('think\swoole\Websocket');
        //
        $roomobj = app('think\swoole\websocket\Room');

        // $ws->getSender()  fd  => $event['room']
        // 当前客户端加入指定Room
        $ws->join($event['room']);

        // 指定客户端加入到指定的Room
        //ws->setSender(2)->join($event['room']);

        // 当前客户端加入多个指定Room
        //$ws->join(['room1', 'room2']);

        // 指定客户端加入到指定的Room
        //ws->setSender(2)->join([...]);



        // 获取指定房间下有哪些客户端
        //var_dump($roomobj->getClients($event['room']));
        // 获取指定客户端加入了哪些房间
        //var_dump($roomobj->getRooms($ws->getSender()));
        //var_dump($event);

        //$ws->emit('joincallback', '房间加入成功了');

    }    
}
